<?php global $has_permit; ?>
<div class="std_header auto_height">
    <div class="left">
        <strong><?php echo $module['title']; ?></strong>
    </div>
    <div class="right">
        <button class="gray_btn" onclick="admin_site_admin.create_new()"><span>Thêm mới</span></button>
    </div>
</div>
<div class="auto_height clearfix">
    <div class="db_left bl">
        <?php $this->load->view('site/admin/side_block'); ?>
        <?php if ($has_permit && isset($roles) && count($roles) > 0) :?>
        <div class="db_side_block">
            <div class="db_side_header">
                <strong>[Danh sách vai trò]</strong>
            </div>
            <div class="db_inner_content">
                <ul class="lst_role">
                    <li data-id="role_all">
                        <label>
                            <input onclick="return admin_site_admin.filter_by_role(0)" checked="checked" name="rd_name" class="std_rd" type="radio" id="rd_all" />
                            <span class="icon icon_role"></span>
                            <strong>[#]. Tất cả</strong>
                        </label>
                    </li>
                    <?php foreach ($roles as $role) :?>
                    <li data-id="role_<?php echo $role->id; ?>">
                        <label>
                            <input onclick="admin_site_admin.show_role_privileges(<?php echo $role->id; ?>, 'block_privileges'); return admin_site_admin.filter_by_role(<?php echo $role->id; ?>)" name="rd_name" class="std_rd" type="radio" id="rd_<?php echo $role->id; ?>" />
                            <span class="icon icon_role"></span>
                            <strong>[#<?php echo $role->id; ?>]. <?php echo $role->name; ?></strong>
                        </label>
                    </li>
                    <?php endforeach; ?>
                </ul>
            </div>
        </div>
        <?php endif; ?>
        <div id="block_privileges"></div>
    </div>
    <div class="db_right bl">
        <?php if ($has_permit) :?>
        <div id="admin_management">
            <div id="tab_store" class="tab_container">
                <ul>
                    <li id="active_tab_list"><a href="#tab_list"><span>Danh sách người dùng</span></a></li>
                    <li id="active_tab_edit"><a href="#tab_edit"><span>Thông tin người dùng</span></a></li>
                </ul>
                <div id="tab_list">
                    <?php if (count($collection) != 0) : ?>
                    <?php $this->load->view('site/admin/message'); ?>
                    <form data-result-id="lst_user" class="ajax_form" id="frm_admin_grid" action="<?php echo site_url('admin/site/admin/ajax_filter', true); ?>" method="post">
                        <div class="block" id="lst_user">
                            <table class="gridview" width="100%" cellpadding="0" cellspacing="0" border="0">
                                <thead>
                                <tr>
                                    <td><b>ID</b></td>
                                    <td><b>Tên</b></td>
                                    <td><b>Tên đăng nhập</b></td>
                                    <td><b>Chức vụ</b></td>
                                    <td><b>Kích hoạt</b></td>
                                    <td><b>Email</b></td>
                                    <td><b>Thao tác</b></td>
                                </tr>
                                </thead>
                                <tbody>
                                <tr class="filters">
                                    <td>
                                        <input placeholder="ID" type="text" class="small_filter" name="filters[a.id][value]" />
                                        <input type="hidden" value="equal" name="filters[a.id][type]" />
                                    </td>
                                    <td colspan="3">
                                        <input placeholder="Tên người dùng / Username / Email" type="text" class="wide_filter" name="filters[a.name][value]" />
                                        <input type="hidden" value="text" name="filters[a.name][type]" />
                                    </td>
                                    <td colspan="2">
                                        <select style="width: 99%" id="filters_is_active" name="filters[is_active][value]" onchange="$('#frm_admin_grid').submit()">
                                            <option value="-1">Tất cả trạng thái</option>
                                            <option value="1">Đã kích hoạt</option>
                                            <option value="0">Chưa kích hoạt</option>
                                        </select>
                                        <input type="hidden" value="equal" name="filters[is_active][type]" />
                                        <input type="hidden" value="-1" name="filters[is_active][exclude]" />
                                    </td>
                                    <td width="200px">
                                        <button class="gray_btn" type="submit" onclick="admin_site_admin.act_filter();">
                                            <span>Lọc</span>
                                        </button>
                                        <button class="gray_btn" type="button" onclick="admin_site_admin.reset_filters();">
                                            <span>Xóa lọc</span>
                                        </button>
                                    </td>
                                </tr>
                                <tr id="filter_empty" style="display: none">
                                    <td colspan="7"><p align="center">Không tìm thấy người dùng theo tiêu chí tìm kiếm</p></td>
                                </tr>
                                <?php foreach ($collection as $admin) : ?>
                                <tr data-id="<?php echo $admin->id; ?>" data-name="<?php echo $admin->name; ?> <?php echo $admin->username; ?> <?php echo $admin->email; ?>" data-role-id="<?php echo $admin->role_id; ?>" data-is-active="<?php echo $admin->is_active; ?>">
                                    <input type="hidden" value="" class="edit_url" />
                                    <td width="30px" valign="top">
                                        <?php echo $admin->id; ?>
                                    </td>
                                    <td valign="top">
                                        <?php echo $admin->name; ?>
                                    </td>
                                    <td valign="top">
                                        <?php echo $admin->username; ?>
                                    </td>
                                    <td valign="top">
                                        <a target="_blank" href="<?php echo site_url('admin/site/role/edit/id/' . $admin->role_id, true); ?>"><?php echo $admin->role_name; ?></a>
                                    </td>
                                    <td valign="top">
                                        <?php if ($admin->is_active == 1) :?>
                                            <span class="icon icon_active"></span>
                                        <?php else :?>
                                            <span class="icon icon_deactive"></span>
                                        <?php endif; ?>
                                    </td>
                                    <td valign="top">
                                        <?php echo $admin->email; ?>
                                    </td>
                                    <td valign="top">
                                        <p><a class="ajax_link icon icon_edit" data="{id:<?php echo $admin->id; ?>}" selector="#tab_edit" item="#active_tab_edit a" href="<?php echo site_url('admin/site/admin/ajax_edit/id/' . $admin->id, true); ?>"></a> <a class="icon icon_delete" href="<?php echo site_url('admin/site/admin/delete/id/' . $admin->id, true); ?>" onclick="return confirm('Bạn muốn xóa người dùng này?')"></a></p>
                                    </td>
                                </tr>
                                <?php endforeach; ?>
                                </tbody>
                                <tfoot></tfoot>
                            </table>
                        </div>
                    </form>
                    <?php else : ?>
                    <div class="error_message corner">Không có người dùng nào</div>
                    <?php endif; ?>
                </div>
                <div id="tab_edit">
                    <form id="frm_admin_edit" method="POST" action="<?php echo $save_action; ?>">
                        <div class="clearfix auto_height mb_10">
                            <button class="gray_btn active_item" type="button" item="#active_tab_list a"><span>Về danh sách</span></button>
                            <button class="gray_btn" type="submit"><span>Lưu lại</span></button>
                            <button class="gray_btn" type="reset"><span>Nhập lại</span></button>
                        </div>
                        <div class="form_block">
                            <div class="block_header">
                                Thông tin căn bản
                            </div>
                            <div class="block_content">
                                <table cellpadding="0px" cellspacing="0px">
                                    <tr>
                                        <td class="frm_label">Tên đăng nhập(*)</td>
                                        <td class="frm_field">
                                            <input type="text" class="std_input required" name="data[username]" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="frm_label">Tên người dùng(*)</td>
                                        <td class="frm_field">
                                            <input type="text" class="std_input required" name="data[name]" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="frm_label">Kích hoạt(*)</td>
                                        <td class="frm_field">
                                            <label>
                                                <input value="1" type="checkbox" class="std_chk" name="data[is_active]" />
                                                <span>Có / Không</span>
                                            </label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="frm_label">Là tài khoản hệ thống(*)</td>
                                        <td class="frm_field">
                                            <label>
                                                <input value="1" type="checkbox" class="std_chk" name="data[is_system]" />
                                                <span>Có / Không</span>
                                            </label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="frm_label">Chức vụ(*)</td>
                                        <td class="frm_field">
                                            <select name="data[role_id]" style="width: 180px">
                                                <?php foreach ($roles as $role) :?>
                                                <option value="<?php echo $role->id; ?>"><?php echo $role->name; ?></option>
                                                <?php endforeach; ?>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="frm_label">Mật khẩu(*)</td>
                                        <td class="frm_field">
                                            <input type="password" class="std_input" name="data[password]" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="frm_label">Điện thoại</td>
                                        <td class="frm_field">
                                            <input type="text" class="std_input required" name="data[phone]" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="frm_label">Email(*)</td>
                                        <td class="frm_field">
                                            <input type="text" class="std_input required" name="data[email]" />
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                        <div class="clearfix auto_height">
                            <button class="gray_btn active_item" type="button" item="#active_tab_list a"><span>Về danh sách</span></button>
                            <button class="gray_btn" type="submit"><span>Lưu lại</span></button>
                            <button class="gray_btn" type="reset"><span>Nhập lại</span></button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <?php else :?>
            <?php $this->load->view('layouts/restricted'); ?>
        <?php endif; ?>
    </div>
</div>
<script type="text/javascript">
    $("#frm_admin_edit").validate();
</script>
<script type="text/javascript" src="<?php echo BASE_URL; ?>js/admin/site/admin/function.js"></script>